<?php
// 本文档自动生成，仅供测试运行
class IndexAction extends Action
{
    /**
    +----------------------------------------------------------
    * 默认操作
    +----------------------------------------------------------
    */
    public function index()
    {
		
		
        //$user = Cookie::get ('lh_account');
		//$map['uid'] = $user['userid'];
		$map = '';
		$model = D('Goods');
		$list= $model->where($map)->select();
		$count = count($list);
         if ($count > 0) {
			import ( "@.ORG.Page" );
			//创建分页对象
			if (! empty ( $_REQUEST ['listRows'] )) {
				$listRows = $_REQUEST ['listRows'];
			} else {
				$listRows = '12';//设置分页显示数量
			}
			$p = new Page ( $count, $listRows );
			//分页查询数据
			$voList = $model->where($map)->limit($p->firstRow . ',' . $p->listRows)->findAll ( );
			//分页跳转的时候保证查询条件
			foreach ( $map as $key => $val ) {
				if (! is_array ( $val )) {
					$p->parameter .= "$key=" . urlencode ( $val ) . "&";
				}
			}
			//分页显示
			$page = $p->show ();
			//列表排序显示
			//模板赋值显示
			$this->assign ( 'list', $voList );
			$this->assign ( "page", $page );
		}
		
		$this->display();
    }
	
	
    public function import()
    {
        //$this->display(THINK_PATH.'/Tpl/Autoindex/hello.html');
		  import ( '@.ORG.Baidu' );
		  $c=new Baidu();
		  $data = array();
		  $a=!empty($_GET['act'])?$_GET['act']:1;
		  $url = $c->url($a);
		  $data = $c->get($url);
		  
		  $model = M('Goods');
		  //print_r($data);
		  foreach($data as $d)
		  {
			  $d['title'] = iconv( "gb2312" , "UTF-8", $d['title']);
			  $d['cat']   = iconv( "gb2312" , "UTF-8", $d['cat']);
			  $d['url']   = iconv( "gb2312" , "UTF-8", $d['url']);
			  $d['img']   = iconv( "gb2312" , "UTF-8", $d['img']);
			  
			  if(chack_title($d['title'])<=0){
		      if(false != $model->data($d)->add()){
		      echo '导入成功<br>';
			  }
			  }
		  }
		  
          $this->display();

    }
	
    public function update_url()
    {
		
	   $model = M("Goods"); 
       $list  = $model->select();
	   foreach($list as $r){
		$map['url']   = $r['url'];
		$data['url']  = str_replace('baidutuan_tg','sharemt_tg',$r['url']);
		$model->where($map)->save($data); 
	   }

	   
    }
	

    /**
    +----------------------------------------------------------
    * 探针模式
    +----------------------------------------------------------
    */
    public function checkEnv()
    {
        load('pointer',THINK_PATH.'/Tpl/Autoindex');//载入探针函数
        $env_table = check_env();//根据当前函数获取当前环境
        echo $env_table;
    }

}
?>